package model;

import java.util.*;

public class IniEquipmentDateModel {
    private String ip;
    private int port;
    private int address;
    private int channel;
    private Date dateNow;
    private String batchId;
    private List<DataBatchModel> dataBatchModels;

    public IniEquipmentDateModel() {
//        this.dataBatchModels = new ArrayList<>(16);
    }

    public void Close(){
        this.dataBatchModels.clear();
    }
    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        this.dataBatchModels.clear();
    }

    public List<DataBatchModel> getDataBatchModels() {
        return dataBatchModels;
    }

    public List<DataBatchModel> getDataBatchModelsBySort() {
        Collections.sort(dataBatchModels, new Comparator<DataBatchModel>() {
            @Override
            public int compare(DataBatchModel o1, DataBatchModel o2) {
                float diff = o1.getWaveValue() - o2.getWaveValue();
                if (diff > 0) {
                    return 1;
                }else if (diff < 0) {
                    return -1;
                }
                return 0; //相等为0
            }
        });
        return dataBatchModels;
    }

    public void setDataBatchModels(List<DataBatchModel> dataBatchModels) {
        this.dataBatchModels = dataBatchModels;
    }

    public String getBatchId() {
        return batchId;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public int getAddress() {
        return address;
    }

    public void setAddress(int address) {
        this.address = address;
    }

    public int getChannel() {
        return channel;
    }

    public void setChannel(int channel) {
        this.channel = channel;
    }

    public Date getDateNow() {
        return dateNow;
    }

    public void setDateNow(Date dateNow) {
        this.dateNow = dateNow;
    }

    /**
     * @param lastWriteTime      最后写入时间
     * @param date               当前时间
     * @param equipmentWriteTime 时间间隔
     * @return 是否为新批次
     */
    public boolean isNewBatch(Date lastWriteTime, Date date, long equipmentWriteTime) {
        return lastWriteTime.getTime() - date.getTime() > equipmentWriteTime ? true : false;
    }

    public void setBatchId(String batchId) {
        this.batchId = batchId;
    }

}
